package edu.tcc.iot.controler.impl;

import java.net.Socket;
import java.util.HashSet;
import java.util.Set;
import org.apache.log4j.Logger;
import edu.tcc.iot.controler.IShelfController;
import edu.tcc.iot.core.services.IConnectionService;
import edu.tcc.iot.utils.ServiceLocator;

public class ShelfController implements IShelfController {
	
	private final static Logger log = Logger.getLogger(ShelfController.class); 
	private IConnectionService connectionService = ServiceLocator.getInstance(IConnectionService.class);
	private static Set<ShelfThread> shelfThreads = new HashSet<ShelfThread>();
    
   
    public void run(){
    	log.info("[CERS][ShelfController] Shelf Controller Thread Initialized");
            while(true){
                    try {
                    	Socket socket = connectionService.getConnection();
                    	ShelfThread shelfThread = new ShelfThread(socket);
                    	shelfThreads.add(shelfThread);
                    	new Thread(shelfThread).start();
						Thread.sleep(20000);
					} catch (InterruptedException e) {
						log.error(e.getMessage());
					}
            }
    }
}
